package com.lanxin.oa.personnel.service;
import com.lanxin.bean.ZzAdjustment;
import com.lanxin.bean.ZzEmployee;
import com.lanxin.oa.personnel.dao.AdjustDao;
import com.lanxin.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;

@Service
public class AdjustDaoServiceImpl implements AdjustDaoService{
    @Autowired
    private AdjustDao adjustDao;
    @Override
    public ZzEmployee selectEmpById(Integer oid) {
        return adjustDao.selectEmpById(oid);
    }

    @Override
    public boolean insertAdjust(ZzAdjustment zzAdjustment) {
        ZzEmployee employee=adjustDao.selectByIdAdjust(zzAdjustment.getEmpid());
        zzAdjustment.setAdjustDate(new Date());
        employee.getZzAdjustments().add(zzAdjustment);
        employee.setDeptid(zzAdjustment.getDestdeptid());
        employee.setJobid(zzAdjustment.getDestjobid());
        try {
            adjustDao.update(employee);
        } catch (Exception e) {
            e.printStackTrace();
            return  false;
        }
        return true;
    }

    @Override
    public PageBean<ZzAdjustment> getAdjustPage(Integer page, Integer pageSize, Integer empid, Date startDate,Date endDate) {
        return adjustDao.selectAdjustPage(page,pageSize,empid,startDate,endDate);
    }

}
